package wechat

import (
	"fmt"
	"gitee.com/small_fish_official_net/more_wechat/model/https"
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/logs"
	"github.com/robertkrimen/otto"
	"time"
)

// 获取UUID信息
func get_uuid()string{
	login,err := https.GetNoCookie("https://login.wx.qq.com/jslogin?appid=wx782c26e4c19acffb&fun=new&lang=zh_CN&_="+fmt.
		Sprintf("%d",time.Now().Unix())+"&redirect_uri="+beego.AppConfig.String("Wechat::domain"))
	if err != nil {
		logs.Error("获取微信uuid失败，原因："+err.Error())
		return ""
	}
	vm := otto.New()
	vm.Run("window = {QRLogin:{code:200,uuid:0}};"+login)
	if value, err := vm.Get("window"); err == nil {
		if value,err := value.Object().Get("QRLogin");err == nil {
			if value,err := value.Object().Get("uuid");err == nil {
				return value.String()
			}
		}
	}
	logs.Error("UUID获取失败，原因："+err.Error())
	return ""
}